package exercise5;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.*;
public class DiagonalOfPlus {
	protected Logger logger = LogManager.getLogger(this.getClass().getName());
	public  int[][] addMatrix(int[][] m1, int[][] m2) {
		int[][] m3=new int[m1.length][m1.length];
		StringBuilder str=new StringBuilder();
		str.append("\n");
		if(m1.length!=m2.length) {
			this.logger.debug("对不起您输入的两个数字维数不对应");
		}
		else {
			for(int i=0;i<m3.length;i++) {
				for(int j=0;j<m3.length;j++) {
					m3[i][j]=m1[i][j]+m2[i][j];
				}
			}
			int count=0;
			this.logger.debug("The addition of the matrices is");
			for(int i=0;i<m3.length;i++) {
				count++;
				for(int j=0;j<m3.length;j++) {
					str.append(m1[i][j]+" ");
				}
				if(count==m3.length/2+1) {
					str.append("\t+\t");
				}
				else {
					str.append("\t \t");
				}
				for(int k=0;k<m3.length;k++) {
					str.append(m2[i][k]+" ");
				}
				if(count==m3.length/2+1) {
					str.append("\t=\t");
				}
				else {
					str.append("\t \t");
				}
				for(int k=0;k<m3.length;k++) {
					str.append(m3[i][k]+" ");
				}
				str.append("\n");
			}	
			this.logger.debug(str.toString());
		}

		return null;
	}
	public void print() {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		this.logger.debug("请输入第一个二维数组的长度：");
		int p = sc.nextInt();
		this.logger.debug("请输入第一个二维数组的数值：");
		int[][] arr1 = new int[p][p];
		for (int i = 0; i < arr1.length; i++) {
			for (int j = 0; j < arr1.length; j++) {
				arr1[i][j] = sc.nextInt();
			}
		}
		this.logger.debug("请输入第二个二维数组的长度：");
		int m = sc.nextInt();
		this.logger.debug("请输入第二个二维数组的数值：");
		int[][] arr2 = new int[m][m];
		for (int i = 0; i < arr2.length; i++) {
			for (int j = 0; j < arr2.length; j++) {
				arr2[i][j] = sc.nextInt();
			}
		}
		this.logger.debug(addMatrix(arr1,arr2));
	}
}
